



var typeidutil='';
$(function(){
	var typeid = getQueryString("typeid") ;
	if(typeid!=null && typeid !=''){
		typeidutil = typeid;
		init(typeid);
	}else{
		var sysid = getQueryString("sysid") ;
//		var sysid='66f2580de486443a8b1d6765fca33b4a';
		if(sysid!=null && sysid !=''){
			queryXyMsg(sysid);
		
		}
	}
	
	
	
	
})

function init(typeid){
	//类别  1信用监督 2信用咨询 3信用申报 4信用异议
	$("#xyfwMenuId li").removeClass();
	if(typeid==1){
		$("#xyjdId").attr("class","presentnav");
		//1信用监督
		$("#titleId").html("信用监督");
		$("#titleIdb").html("信用监督");
		$("#xmId").html("投诉人姓名");
		$("#sfzhmId").html("身份证号码");
		$("#lxdhId").html("联系电话");
		$("#emailId").html("联系邮箱");
		$("#dsztId").html("投诉主题");
		$("#messageId").html("投诉内容");
		
	}else if(typeid==2){
		$("#xyzxId").attr("class","presentnav");
		//2信用咨询 
		$("#titleId").html("信用咨询");
		$("#titleIdb").html("信用咨询");
		$("#xmId").html("姓名");
		$("#sfzhmId").html("身份证号码");
		$("#lxdhId").html("联系电话");
		$("#emailId").html("电子邮件");
		$("#dsztId").html("咨询主题");
		$("#messageId").html("咨询内容");

	}else if(typeid==3){
		$("#xysbId").attr("class","presentnav");
		//3信用申报
		$("#titleId").html("信用申报");
		$("#titleIdb").html("信用申报");
		$("#xmId").html("申报人姓名");
		$("#sfzhmId").html("身份证号码");
		$("#lxdhId").html("联系电话");
		$("#emailId").html("电子邮件");
		$("#dsztId").html("举报项目名称");
		$("#messageId").html("举报项目名称");

	}else if(typeid==4){
		$("#xyyiId").attr("class","presentnav");
		// 4信用异议
		$("#titleId").html("信用异议");
		$("#titleIdb").html("信用异议");
		$("#xmId").html("投诉人姓名");
		$("#sfzhmId").html("身份证号码");
		$("#lxdhId").html("联系电话");
		$("#emailId").html("联系邮箱");
		$("#dsztId").html("信用记录编号");
		$("#messageId").html("详细描述");
	}else{
		$("#submit").hide();
		return;
	}
	
}
//添加信息
function addMsg(){
	var xm = $("#xm").val().replace(/\s/g, "");
	var sfzhm = $("#sfzhm").val().replace(/\s/g, "");
	var phone = $("#lxdh").val().replace(/\s/g, "");
	var email = $("#email").val().replace(/\s/g, "");
	var mc = $("#tszt").val().replace(/\s/g, "");
	var content = $("#yyms").val().replace(/\s/g, "");
	var attachment = $("#hideUrlId").val().replace(/\s/g, "");
	
	var isture= yzparms(xm,sfzhm,lxdh,email,tszt,phone,mc);
	if(isture==false){
		return;
	}
	
	$.ajax({
		  type: "post",
		  url: "../../xyService/addXyService",
		  data: {
			  'type':typeidutil,
			  'xm':xm,
			  'sfzhm':sfzhm,
			  'phone':phone,
			  'email':email,
			  'mc':mc,
			  'content':content,
			  'attachment':attachment
		  },
		  dataType: "json",
		  success: function(data){
			  var row = data.row;
			  var mess = data.mess;
			  if(mess=="未登录"){
				  alert('请先登录！');
				  MM_showHideLayers('loginbg','','show');
			  }
			  if(row==1){
				  alert("添加成功");
				  var menu = "";
				  if(typeidutil==1){
					  menu = 72;
				  }else if(typeidutil==2){
					  menu = 73;
				  }else if(typeidutil==3){
					  menu = 75;
				  }else if(typeidutil==4){
					  menu = 74;
				  }
				  location.href="page_service_complain.html?parent=71&menu="+menu+"&fwtype="+typeidutil;
			  }else{
				  alert("添加失败");
			  }
		  }
	})
}

function yzparms(xm,sfzhm,lxdh,email,tszt,phone,mc){
	if(xm==''){
		$("#xm").css("border-color","red");
	}else{
		$("#xm").css("border-color","#cccccc");
	}
	if(sfzhm==''){
		$("#sfzhm").css("border-color","red");
	}else{
		$("#sfzhm").css("border-color","#cccccc");
	}
	if(phone==''){
		$("#lxdh").css("border-color","red");
	}else{
		$("#lxdh").css("border-color","#cccccc");
	}
	if(email==''){
		$("#email").css("border-color","red");
	}else{
		$("#email").css("border-color","#cccccc");
	}
	if(mc==''){
		$("#tszt").css("border-color","red");
	}else{
		$("#tszt").css("border-color","#cccccc");
	}
	if(xm==''|| sfzhm=='' || lxdh==''||email==''||tszt==''||phone==''||mc==''){
		return false;
	}
	//验证邮箱的正则表达式判断
	var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 
	if(!reg.test(email)){
	     alert("邮箱格式不对");
	     $("#email").css("border-color","red");
	     return false;
	 }
}

//查询信用信息
function queryXyMsg(sysId){
	$.ajax({
		  type: "post",
		  url: "../../xyService/queryXyService",
		  data: {
			  'sysId':sysId
		  },
		  dataType: "json",
		  success: function(data){
			  var list = data.list;
			  if(list!=null && list.length >0){
				  var entity = list[0];
				  typeidutil = entity.type;
				  init(typeidutil);
				  $("#xm").html(entity.xm);
				  $("#sfzhm").html(entity.sfzhm);
				  $("#lxdh").html(entity.phone);
				  $("#email").html(entity.email);
				  $("#tszt").html(entity.mc);
				  $("#yyms").html(entity.content);
				  if(entity.attachment !=null && entity.attachment !=''){
					  //var downStr = '../down/'+entity.attachment;
					  var urlStr = entity.attachment;
					  var urlsplit = urlStr.split(",");
					  for(var i = 1;i<urlsplit.length;i++){
						  if(urlsplit[i]!=null && urlsplit[i]!=''){
							  var urlAndName = urlsplit[i].split("(&split&)");
							  var downUrl = '../down/'+urlAndName[0];
							  var strdown = '<a   class="textloding" href="'
								  +downUrl
								  +'">'
								  +urlAndName[1]
								  +'</a>';
							  $("#attachmentId").append(strdown);
						  }
					  }
					 
					  
				  }else{
					  var noneStr='<a    class="textloding" href="#">暂无附件</a>';
					  $("#attachmentId").append(noneStr);
				  }
				  
			  }
		  }
	})
}



function fn_uploadinit(){
	fn_upload("myhead","hideUrlId");
}



//图片上传
function fn_upload(fileObjectId,hideUrlId){
	 var hideUrlVal = $("#"+hideUrlId).val();
	 
	 var fileurl = hideUrlVal.split(",");
	 
	 if(fileurl.length>3){
		 alert("文件上传最大数量3个");
		 return;
	 }
	  var url = '../upload/fileUpload';
	  var suffixStr = "jpg,png,gif,pdf,zip,rar,xls,xlsx,docx,doc";
	  var savePath = ",down";/* 文件存储路径 */
	  $.ajaxFileUpload({
          url: url+'?fileObjectId='+fileObjectId+'&MaxSize='+2048+'&suffixStr='+suffixStr+'&savePath='+savePath+'&width='+0+'&height='+0, //用于文件上传的服务器端请求地址
          secureuri: false, //是否需要安全协议，一般设置为false
          fileElementId: fileObjectId, //文件上传域的ID
          dataType: 'json', //返回值类型 一般设置为json
          success: function (data, status)  //服务器成功响应处理函数
          {
              if(data.success=="true"){
            	  var oldval = $("#"+hideUrlId).val();
            	  var pid = data.imgurl.split(".");
            	  
            	  $("#"+hideUrlId).val(oldval+","+data.imgurl+"(&split&)"+data.oldname);
            	  var fileloadStr='<span id="'+pid[0]+'">'
            	  		+'<p class="text_indent_120 pfileloding">'
            		  	+data.oldname
						+'</p><input id="submit3" type="button" onclick="delfile('+"'"+data.imgurl+"'"+','+"'"+data.oldname+"'"+')" value="删 除"/></span>';
            	 
            	  $("#fileloadId").append(fileloadStr);
            	  alert("附件上传成功!");
            	  
            	
              }else{
           	   	  alert(data.msg);
            		return;
              }
          },
          error: function (data, status, e)//服务器响应失败处理函数
          {
       	   		alert(e);
				return;
          }
   })
} 
//删除文件
function delfile(url,oldname){
	 if(confirm("确定删除此附件吗?")){
		 var pid = url.split(".");
		 $("#"+pid).remove();
		 
		 var hideUrlVal = $("#hideUrlId").val();
		 var delurl = ","+url+"(&split&)"+oldname;
		 hideUrlVal=hideUrlVal.replace(delurl, "");
		 $("#hideUrlId").val(hideUrlVal);
		 $.ajax({
			  type: "post",
			  url: "../../xyService/delFile",
			  data: {
				  'fileurlStr':delurl,
				  'fileurl':url
			  },
			  dataType: "json",
			  success: function(data){
				  
			  }
		})
	 }
	
}


//获取参数值
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null){
    	return unescape(r[2]);
    }else{
    	return null;
    } 
 }